<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>偶尔有点困-后台登录</title>
		<link rel="shortcut icon" href="/favicon.ico" />
		<link rel="bookmark" href="/favicon.ico" />
		<link rel="stylesheet" href="../plugins/layui/css/layui.css" />
		<link rel="stylesheet" href="../css/admin/login/login.css" />
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 8]>
		<script type="text/javascript" src="plugins/ace/js/buttons.html5.min.js" ></script>
		<script type="text/javascript" src="plugins/ace/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
		<div class="layui-container">
			<div class="layadmin-user-login-main center">
				<form id="login" class="layadmin-user-login-box layadmin-user-login-body layui-form">
					<div class="layui-form-item">
						<div class="logo">
							<img src="https://spring.io/img/homepage/icon-spring-cloud-data-flow.svg" />
						</div>
						<h3 class="title">欢迎来到纯真年代后台管理系统</h3>
					</div>
					<div class="layui-form-item">
						<input name="username" lay-verify="required" placeholder="默认账号guest" class="my-layui-input" type="text">
					</div>
					<div class="layui-form-item">
						<input name="password" lay-verify="required|password" placeholder="默认密码guest" class="my-layui-input" type="password">
					</div>
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<input type="hidden" name="code" />
								<input type="text" name="codeStr" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="my-layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<img id="codeImg" src="https://www.oschina.net/action/user/captcha" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<button class="my-layui-btn" lay-submit lay-filter="LAY-user-login-submit">Login</button>
					</div>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../plugins/layui/layui.js"></script>
	<script type="text/javascript">
		layui.config({
			base: '../js/admin/' //静态资源所在路径
		}).extend({
			common: '/common' //公共模块
		}).use(['common'], function() {
			var common = layui.common,
				layer = common.layer,
				form = common.form,
				$ = common.$;
				var menu =[{"id":13,"parentid":0,"name":"权限中心","ico":"layui-icon layui-icon-auz","href":"","type":1,"permission":"","sort":30},{"id":38,"parentid":6,"name":"添加文章","ico":null,"href":"","type":2,"permission":"sys:article:add","sort":100},{"id":27,"parentid":25,"name":"删除字典","ico":null,"href":"","type":2,"permission":"sys:dictionary:del","sort":100},{"id":51,"parentid":2,"name":"查询信息","ico":null,"href":"","type":2,"permission":"web:user:query","sort":100},{"id":50,"parentid":2,"name":"修改状态","ico":null,"href":"","type":2,"permission":"web:user:upstatus","sort":100},{"id":26,"parentid":25,"name":"添加字典","ico":null,"href":"","type":2,"permission":"sys:dictionary:add","sort":100},{"id":24,"parentid":0,"name":"系统管理","ico":"layui-icon layui-icon-set","href":"","type":1,"permission":"","sort":50},{"id":9,"parentid":1,"name":"管理员列表","ico":null,"href":"users/admin/admin_list.html","type":1,"permission":"","sort":22},{"id":20,"parentid":14,"name":"添加菜单","ico":null,"href":"","type":2,"permission":"sys:menu:add","sort":100},{"id":29,"parentid":25,"name":"查询字典信息","ico":null,"href":"","type":2,"permission":"sys:dictionary:query","sort":100},{"id":16,"parentid":15,"name":"添加角色","ico":null,"href":"","type":2,"permission":"sys:role:add","sort":100},{"id":28,"parentid":25,"name":"修改字典","ico":null,"href":"","type":2,"permission":"sys:dictionary:update","sort":100},{"id":25,"parentid":24,"name":"字典管理","ico":null,"href":"system/dictionary/dictionary_list.html","type":1,"permission":"","sort":52},{"id":15,"parentid":13,"name":"角色管理","ico":null,"href":"permission/role/role_list.html","type":1,"permission":"","sort":100},{"id":23,"parentid":14,"name":"查询菜单信息","ico":null,"href":"","type":2,"permission":"sys:menu:query","sort":100},{"id":5,"parentid":4,"name":"发布文章","ico":null,"href":"article/article_add.html","type":1,"permission":"","sort":11},{"id":53,"parentid":36,"name":"更新网站信息","ico":null,"href":"","type":2,"permission":"sys:website:update","sort":100},{"id":45,"parentid":35,"name":"查询浏览","ico":null,"href":"","type":2,"permission":"sys:classifyLabel:query","sort":100},{"id":2,"parentid":1,"name":"用户管理","ico":null,"href":"users/web/qquser_list.html","type":1,"permission":"","sort":21},{"id":6,"parentid":4,"name":"文章管理","ico":null,"href":"article/article_list.html","type":1,"permission":"","sort":12},{"id":36,"parentid":24,"name":"网站设置","ico":null,"href":"system/web_setting.html","type":1,"permission":"","sort":53},{"id":21,"parentid":14,"name":"删除菜单","ico":null,"href":"","type":2,"permission":"sys:menu:del","sort":100},{"id":32,"parentid":31,"name":"文件上传","ico":null,"href":"","type":2,"permission":"file:upload","sort":100},{"id":34,"parentid":31,"name":"查看文件","ico":null,"href":"","type":2,"permission":"file:query","sort":100},{"id":3,"parentid":9,"name":"添加管理员","ico":null,"href":"","type":2,"permission":"sys:admin:add","sort":23},{"id":14,"parentid":13,"name":"菜单管理","ico":null,"href":"permission/menu/menu_list.html","type":1,"permission":"","sort":100},{"id":4,"parentid":0,"name":"文章","ico":"layui-icon layui-icon-read","href":"","type":1,"permission":"","sort":10},{"id":44,"parentid":35,"name":"修改信息","ico":null,"href":"","type":2,"permission":"sys:classifyLabel:addUp","sort":100},{"id":47,"parentid":46,"name":"密码修改","ico":null,"href":"users/update_my_password.html","type":1,"permission":"","sort":41},{"id":48,"parentid":46,"name":"个人信息修改","ico":null,"href":"users/update_my_base_info.html?v=1.0","type":1,"permission":"","sort":42},{"id":11,"parentid":9,"name":"查询","ico":null,"href":"","type":2,"permission":"sys:admin:query","sort":25},{"id":42,"parentid":35,"name":"添加","ico":null,"href":"","type":2,"permission":"sys:classifyLabel:addUp","sort":100},{"id":43,"parentid":35,"name":"删除","ico":null,"href":"","type":2,"permission":"sys:classifyLabel:del","sort":100},{"id":19,"parentid":15,"name":"查询角色信息","ico":null,"href":"","type":2,"permission":"sys:role:query","sort":100},{"id":18,"parentid":15,"name":"修改角色","ico":null,"href":"","type":2,"permission":"sys:role:update","sort":100},{"id":33,"parentid":31,"name":"删除文件","ico":null,"href":"","type":2,"permission":"file:del","sort":100},{"id":1,"parentid":0,"name":"用户中心","ico":"layui-icon layui-icon-user","href":"","type":1,"permission":"","sort":20},{"id":39,"parentid":6,"name":"删除文章","ico":null,"href":"","type":2,"permission":"sys:article:del","sort":100},{"id":35,"parentid":4,"name":"分类、标签","ico":null,"href":"article/article_classify_label.html","type":1,"permission":"","sort":13},{"id":17,"parentid":15,"name":"删除角色","ico":null,"href":"","type":2,"permission":"sys:role:del","sort":100},{"id":52,"parentid":36,"name":"查询信息","ico":null,"href":"","type":2,"permission":"sys:website:query","sort":100},{"id":10,"parentid":9,"name":"单、批量删除管理员","ico":null,"href":"","type":2,"permission":"sys:admin:del","sort":24},{"id":41,"parentid":6,"name":"查询浏览","ico":null,"href":"","type":2,"permission":"sys:article:query","sort":100},{"id":46,"parentid":0,"name":"我的设置","ico":"layui-icon layui-icon-friends","href":"","type":1,"permission":"","sort":40},{"id":31,"parentid":24,"name":"文件管理","ico":null,"href":"system/file/file_list.html","type":1,"permission":"","sort":51},{"id":22,"parentid":14,"name":"修改菜单信息","ico":null,"href":"","type":2,"permission":"sys:menu:update","sort":100},{"id":13,"parentid":0,"name":"权限中心","ico":"layui-icon layui-icon-auz","href":"","type":1,"permission":"","sort":30},{"id":37,"parentid":24,"name":"数据源","ico":null,"href":"http://www.bblog.vip/api/blog-admin/druid","type":1,"permission":"","sort":54},{"id":49,"parentid":2,"name":"删除用户","ico":null,"href":"","type":2,"permission":"web:user:del","sort":100},{"id":12,"parentid":9,"name":"修改信息","ico":null,"href":"","type":2,"permission":"sys:admin:update","sort":26},{"id":40,"parentid":6,"name":"修改文章","ico":null,"href":"","type":2,"permission":"sys:article:update","sort":100}];
			console.log(common.toTree(menu));
			var login = {
				init: function() {
					form.render();
					login.initData();
					login.initSubmit();
					login.initFormCheck();
					login.initVerifyCode();
					login.initSubmit();
					login.bindEvent();
				},
				initData: function() {

				},
				bindEvent: function() {
					$("#codeImg").click(function() {
						login.initVerifyCode();
					});
				},
				initSubmit: function() {
					//提交
					form.on('submit(LAY-user-login-submit)', function(data) {
						var user_data = JSON.stringify(data.field);
						$.ajax({
							url: common.IP + '/api/blog-oauth2/oauth2/login',
							contentType: "application/x-www-form-urlencoded",
							headers: {
								'Authorization': ''
							},
							data: $('#login').serialize(),
							success: function(result, status, xhr) {
								layer.closeAll('loading');
								localStorage.setItem("access_token", result.access_token)
								localStorage.setItem("token_type", result.token_type)
								localStorage.setItem("refresh_token", result.refresh_token)
								localStorage.setItem("expires_in", result.expires_in)
								localStorage.setItem("scope", result.scope)
								layer.msg("登录成功", {
									icon: 1,
									time: 1000
								}, function() {
									parent.window.location.href = 'index.html'
								});
							},
							error: function(xhr, textStatus, errorThrown) {
								login.initVerifyCode();
								common.ajaxError(xhr, textStatus, errorThrown);
							}
						});
						return false;
					});
				},
				initFormCheck: function() {
					form.verify({
						password: [
							/^[\S]{5,16}$/, '密码必须5到16位，且不能出现空格'
						]
					});
				},
				initVerifyCode: function() {
					login.checkAccessToken();
					$.ajax({
						type: 'GET',
						async: false,
						url: common.IP + '/api/blog-oauth2/oauth2/verCode?histCode=' + $("input[name='code']").val(),
						success: function(data) {
							layer.closeAll('loading');
							$("input[name='code']").val(data.code);
							$("#codeImg").attr('src', data.codeStr);
						}
					});
				},
				checkAccessToken: function() {
					var access_token = localStorage.getItem("access_token");
					if(access_token != null && access_token.trim().length != 0) {
						$.ajax({
							type: 'POST',
							headers: {
								'Authorization': localStorage.getItem("access_token") == null ? "" : "Bearer " + localStorage.getItem("access_token")
							},
							async: false,
							url: common.IP + '/api/blog-oauth2/currentUser',
							success: function(data) {
								parent.window.location.href = 'index.html';
							},
							error: function(xhr, textStatus, errorThrown) {
								if(xhr.status == 401) {
									localStorage.removeItem("access_token");
								}
							}
						});
					}
				}
			};
			$(function() {
				login.init();
			});
		});
	</script>
	<script>
	</script>

</html>